/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import de.sql.toolkit.model.Table;

/**
 * @author jkonopka
 * 
 */
public class TableCreateScriptGenerator extends AbstractGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8759440882831308166L;
	private List<AbstractGenerator> writer = new ArrayList<AbstractGenerator>();

	/**
	 * @param table
	 * @param dstPath
	 */
	public TableCreateScriptGenerator(Table table, File dstPath) {
		super(table, dstPath);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.IGenerator#generate()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder sb = new StringBuilder();
		sb.append("CREATE OR UPDATE TABLE ");
		sb.append(getTable().getName());
		sb.append(" ( ");
		for (final AbstractGenerator generator : this.writer) {
			sb.append(generator.generate());
		}
		sb.append("\n); ");
		return sb.toString();
	}

	/**
	 * @param generator
	 */
	public void add(final AbstractGenerator generator) {
		this.writer.add(generator);
	}

}
